package net.csdn.business.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author likun
 * @date 2022/6/17 10:36
 */
public interface ProjectEnum {
    @Getter
    @AllArgsConstructor
    enum AccessLevelEnum {
        /**
         * 等级 浏览者、开发者、管理员
         */
        GUEST(20, "guest", "浏览者"),
        DEVELOPER(30, "developer", "开发者"),
        MANAGER(40, "maintainer", "管理员"),
        ;
        final int code;
        final String desc;
        final String descChinese;

        public static AccessLevelEnum ofCode(int code) throws IllegalArgumentException {
            for (AccessLevelEnum accessLevelEnum : AccessLevelEnum.values()) {
                if (accessLevelEnum.code == code) {
                    return accessLevelEnum;
                }
            }
            throw new IllegalArgumentException("ProjectEnum#VisibilityLevelEnum param error");
        }

        public static AccessLevelEnum ofCodeNull(int code) throws IllegalArgumentException {
            try {
                return ofCode(code);
            } catch (IllegalArgumentException e) {
                return null;
            }
        }
    }

    @Getter
    @AllArgsConstructor
    enum VisibilityLevelEnum {
        /**
         * 项目可见性
         */
        PRIVATE(0, "私有"),
        PUBLIC(20, "公开"),
        ;
        final int code;
        final String desc;

        public static VisibilityLevelEnum ofCode(int code) throws IllegalArgumentException {
            for (VisibilityLevelEnum visibilityLevelEnum : VisibilityLevelEnum.values()) {
                if (visibilityLevelEnum.code == code) {
                    return visibilityLevelEnum;
                }
            }
            throw new IllegalArgumentException("ProjectEnum#VisibilityLevelEnum param error");
        }
    }
}